// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import CM from "../../lib/cache/CM";
import { monitor, selfCls } from "../../lib/common/Decorator";
import UIMgr from "../../lib/ui/UIMgr";
import UINode from "../../lib/ui/UINode";
import DUser from "../cache/DUser";
import UILevel from "./UILevel";

const {ccclass, property} = cc._decorator;

@selfCls
export default class UIHall extends UINode {
    private _select:number;
    protected prefab(): string {
        return "prefab/ui/UIHall"
    }

    protected onEvtShow(): void {
        // this.related("label_coin", "DUser", "coin");
        // this.related("label_tili", "DUser", "tili");
        CM.ins(CM).get(DUser).coin = 10;
        CM.ins(CM).get(DUser).tili = 20;
        this.on_click_btn_level();
    }

    @monitor("DUser/coin")
    on_coin_change(attrName, oldVal, newVal) {
        this["label_coin"].getComponent(cc.Label).string = newVal;
    }

    @monitor("DUser/tili")
    on_tili_change(attrName, oldVal, newVal) {
        this["label_tili"].getComponent(cc.Label).string = newVal;
    }

    on_click_btn_add_coin() {

    }

    pn_click_btn_add_tili() {

    }

    on_click_btn_shop() {

    }

    on_click_btn_setting() {

    }

    on_click_btn_tili() {

    }

    on_click_btn_skin() {
        this._select = 1;
        this.updateSelected();
        UIMgr.ins(UIMgr).close(UILevel);
    }

    on_click_btn_level() {
        this._select = 2;
        this.updateSelected();
        UIMgr.ins(UIMgr).show(UILevel);
    }

    on_click_btn_upgrade() {
        this._select = 3;
        this.updateSelected();
        UIMgr.ins(UIMgr).close(UILevel);
    }

    updateSelected() {
        this["btn_skin"].getChildByName("normal").active = this._select != 1;
        this["btn_skin"].getChildByName("selected").active = this._select == 1;
        this["btn_level"].getChildByName("normal").active = this._select != 2;
        this["btn_level"].getChildByName("selected").active = this._select == 2;
        this["btn_upgrade"].getChildByName("normal").active = this._select != 3;
        this["btn_upgrade"].getChildByName("selected").active = this._select == 3;
    }
}
